import { getAjaxBaseUrl } from '../handler'
import type {
  AjaxPagingResult,
  EliminateEquipmentInfo,
  EliminateEquipmentQueryListParams,
  EliminateEquipmentSaveOrUpdateParams,
} from '@/types'

const controller = getAjaxBaseUrl(
  '/eliminateEquipment',
  '/energy',
)

/** 下载淘汰设备信息数据模版 */
export async function downloadTemplate() {
  const { data } = await request({
    method: 'get',
    url: `${controller}/downloadTemplate`,
    responseType: 'blob',
  })

  downloadByA(
    URL.createObjectURL(data),
    `淘汰设备信息数据模版_${formatTime(
      Date.now(),
      'YYYY-MM-DD_hh-mm-ss',
    )}`,
  )
}

/** 新增或修改淘汰设备信息 */
export function saveOrUpdate(params: Partial<EliminateEquipmentSaveOrUpdateParams>) {
  return post(
    `${controller}/saveOrUpdateEliminateEquipment`,
    params,
  )
}

/** 分页查询淘汰设备信息 */
export function queryList(params: Partial<EliminateEquipmentQueryListParams>) {
  return post<AjaxPagingResult<EliminateEquipmentInfo[]>>(
    `${controller}/queryEliminateEquipmentPage`,
    params,
  )
}

/** 删除淘汰设备信息 */
export function deleteById(id: number) {
  return get(`${controller}/deleteEliminateEquipment`, { id })
}
